from direct.showbase.ShowBase import ShowBase

from direct.actor.Actor import Actor
from panda3d.core import Filename,AmbientLight,DirectionalLight
from panda3d.core import Vec3,Vec4,BitMask32
from panda3d.core import PandaNode,NodePath,Camera,TextNode
from direct.gui.OnscreenText import OnscreenText

import random

class MyApp(ShowBase):
 
    def __init__(self):
        ShowBase.__init__(self)
        # Load the environment model.
        #self.environ = self.loader.loadModel("models/environment")
        #self.environ = self.loader.loadModel("humainvert3.egg")
        OnscreenText(text="JMD EST UN TOTO", style=1, fg=(1,1,1,1),
                        pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)

        self.environ = loader.loadModel("base")      
        self.environ.reparentTo(render)
        self.environ.setPos(2,10,-2)
        self.environ.setScale(.8, .8, .2)
        self.environ.setColor(0.8, 0.8, 1.0, 1.0)
        
        self.modeles=[]
        x=-4
        y=10
        z=-2
        for i in range(3):
            y=y+1
            x=-4
            z=z+1
            for j in range(3):
                #print(i)
                acte = Actor("humainvert3salut",
                                     {"salut":"humainvert3salut-salut"})
            
                # Reparent the model to render.
                acte.reparentTo(self.render)
                # Apply scale and position transforms on the model.
                acte.setScale(.1, .1, .1)
                acte.setPos(x, y, z)
                acte.loop("salut")
                acte.setColor(0.8, 0.8, 1.0, 1.0)
                self.modeles.append(acte)
                x=x+1
        #taskMgr.self.environ.loop("salut")
        
        # Create some lighting
        ambientLight = AmbientLight("ambientLight")
        ambientLight.setColor(Vec4(.3, .3, .3, 1))
        directionalLight = DirectionalLight("directionalLight")
        directionalLight.setDirection(Vec3(5, 5, -5))
        
        directionalLight.setColor(Vec4(1, 1, 1, 1))
        directionalLight.setSpecularColor(Vec4(1, 1, 1, 1))
        render.setLight(render.attachNewNode(ambientLight))
        render.setLight(render.attachNewNode(directionalLight))
        
        taskMgr.add(self.saluer,"salut")
    def saluer(self,task):
        n=random.randrange(len(self.modeles))
        print self.modeles[n]
        self.modeles[n].loop("salut")
        return #task.cont

app = MyApp()
app.run()

